2

I'm trying to display USPS Shipping Zone information but the section of the USPS site I used to scrape this information from has been broken for months and I'm wondering if anyone knows another way to get it in a parsable format?

The page that has been broken for months is here: http://postcalc.usps.gov/Zonecharts/ZoneChartPrintable.aspx?zipcode=931

They have the same chart in a not-so-parsable format here: http://postcalc.usps.gov/Zonecharts/

I do cache this information so it doesn't have to be requested constantly, but the cache is cleared occasionally since the zones do change from time to time.

2

Here is the code that I use to fetch the JSON data that populates http://postcalc.usps.gov/Zonecharts/.

private String getZoneJSON(String zip3Digit) {
    URL url;
    HttpURLConnection con;
    String zoneJSON = null;
    try {
        url = new URL("https://postcalc.usps.com/DomesticZoneChart/GetZoneChart?ZIPCode3Digit=" + zip3Digit + "&ExcelFormat=1");
        con = (HttpURLConnection) url.openConnection();
        con.setRequestMethod("GET");
        con.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36");
        con.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
        con.setRequestProperty("DNT", "1");
        con.setInstanceFollowRedirects(false);
        InputStream h = (InputStream) con.getContent();
        BufferedReader r = new BufferedReader(new InputStreamReader(h));
        zoneJSON = r.readLine();
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }

    return zoneJSON;
}
  • This is perfect, thanks. I hadn't been back to review their new site in a while but am glad they serve up a JSON string now instead of having to parse the HTML. – William W Sep 27 '17 at 17:53
1

You can also calculate the zone based on the distance between the coordinates origin SCF (Sectional Center Facility) and the destination SCF

Zone 1: Non-local zones within a 50 mile radius of the point of origination

Zone 2: 51-150 miles radius

Zone 3: 151-300 miles radius

Zone 4: 301-600 miles radius

Zone 5: 601-1,000 miles radius

Zone 6: 1001-1400 miles radius

Zone 7: 1401-1800 miles radius

Zone 8: 1801 miles and over

Zone 9: ZIP codes assigned for exceptional network circumstances

  • You can fine the SCF for each zip code here: https://fast.usps.com/fast/fastApp/resources/labelListFiles.action
  • You can get the coordinates of the SCF from Google API
  • Once you have the coordinates, there are plenty of ways to calculate the distance between them
  • You can also skip the coordinates and just calculate the distance between the zip codes of the SCF iteself (not the zip codes it serves)
0

The USPS sells a full zone chart for all from-to zip combinations for $63 here: https://postalpro.usps.com/operations/zone-charts

I sent in for one since I haven't been able to find info this anywhere else for months now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.