How to Collect Shipping Rates by Country and Postal Code

Published:

11 minute read

Acar Diveroli
Written by: Acar Diveroli
Identical parcels, each with a different address label; the middle one is lifted, its top blue, its label reading SHIP TO

Shipping rate data is a record of the price the same shipment gets depending on the destination country, postal code, weight and basket value. The delivery address sets the price. The store, however, often picks the currency and the estimated shipping shown on the page from the visitor's IP. If the two locations get mixed up, the measurement is filed under the wrong country. This post covers data sources, the fixed test basket, the split between address and IP, tax lines and the record schema.

Data sources

The cleanest source for a shipping price is the carrier's own rate API. Large carriers publish endpoints that take the origin address, destination country, postal code, weight and dimensions and return a price per service. The FedEx rate API can return the list rate and your account rate together, with surcharges on separate lines. DHL Express's MyDHL API also has a Landed Cost service that estimates duties and taxes next to the rate quote.

These APIs require an account and show your contracted rates. That is enough if your job is to measure carrier cost. If you want to measure what the store charges its customers, there are two more sources:

SourceWhat it givesWhen
Carrier rate APICost per service, surchargesCarrier cost
Store's shipping pageZone table, threshold, delivery timeFirst look, routine checks
Store's cart calculatorThe total the customer seesCases the page doesn't cover

Keep this order. The shipping table a store publishes answers most questions in a single request. Go to the cart calculator only for combinations the table doesn't cover. Don't create orders and don't move on to the payment step. Follow the site's terms and its robots.txt file. We explain how to set the request rate per domain in How to Set Your Scraping Request Rate.

A fixed test basket

To compare countries, every measurement uses the same basket. Product, quantity, weight and box size stay fixed. The only thing that changes should be the destination address. If the basket changes, you can't tell whether a difference comes from the country or the product.

Weight has two forms. Carriers charge for the larger of the actual weight and the volumetric weight. Volumetric weight is the box volume divided by a divisor the carrier publishes. That is why a light but large box is priced like a heavy parcel.

python
def chargeable_weight(kg, length_cm, width_cm, height_cm, divisor):
    volumetric = length_cm * width_cm * height_cm / divisor
    return max(kg, volumetric), volumetric

# the divisor is an example; use the value from your carrier's documentation
print(chargeable_weight(1.2, 40, 30, 20, divisor=5000))  # (4.8, 4.8)
print(chargeable_weight(1.2, 20, 15, 10, divisor=5000))  # (1.2, 0.6)

The same 1.2 kg product counts as 4.8 kg in a 40×30×20 cm box and as 1.2 kg in the small box. The divisor and the rounding rule vary from carrier to carrier. Take both from the documentation, don't guess.

One basket isn't enough for a free-shipping threshold. Build two baskets that sit just below and just above the threshold, for example one and three units of the same product. The only difference between them is the quantity. Also note which amount the threshold looks at: the subtotal before discounts, the discounted amount or the total with tax. A promo code can lower the threshold, so don't use one while measuring.

Country and postal code

Carriers price by zone, and the zone usually comes from the postal code. Addresses on islands or in rural or remote areas of the same country can carry a surcharge. So one code per country isn't enough. Pick at least one big-city code and one remote-area code.

Always store the postal code as text. In the US there are codes like 02108, and in Türkiye the codes for Adana start with 01. UK postcodes such as SW1A 1AA contain letters and a space. A code converted to a number loses the zero at the start.

python
import pandas as pd

df = pd.read_csv("measurements.csv", dtype={"postal_code": "string"})

The trap is silent. In our test, with only 10115 and 02108 in the column, pandas turned it into numbers and the second code became 2108. Once SW1A 1AA was added to the list, the column stayed text. So the error only shows up with some country sets. Make passing dtype a habit.

IP location and delivery address

The store sees two separate locations. One is the delivery address, and it sets the shipping rate. The other is the visitor's IP. From the IP, the store picks the currency, the language version, the estimated shipping on the product page and sometimes the list of countries it ships to.

IP countryDelivery countryWhat you measure
GermanyGermanyThe price a local customer sees
TürkiyeGermanyThe view of an order from abroad
GermanyTürkiyeThe store's export shipping

Change one variable at a time when comparing. If you want the total a local customer sees, the IP country and the delivery country must match. A Residential Proxy sends the request out through a home connection in the country you choose. Before measuring, check that the exit IP really is in that country. We explain how country targeting works in How Country and City Targeting Works in a Proxy.

The cart calculator is a multi-step flow. The product goes into the cart, the country and postal code are entered, the rate is read. If the IP changes between steps, the store may reset the cart or the currency. A Sticky Proxy keeps the same session ID on one exit IP for 1-60 minutes. That is more than enough for one measurement flow.

Duty and tax lines

For a cross-border shipment, the total the customer pays has three parts: shipping, customs duty and import tax. Some stores collect these taxes at checkout. At others, the customer pays them on delivery. If you record the checkout total as a single number, you can't compare the two models.

Write each line to its own column: shipping, duty, tax and any handling fee. Add a tax_paid_at column as well, with checkout or delivery. Tax collected on delivery never appears on the checkout page. For these lines, an empty value means "unknown", not "zero". Keep the two apart.

Don't calculate taxes yourself. The de minimis threshold, product class and rate vary by country and change often. The carrier's duty estimate service asks for the product's customs tariff code (HS code) and returns the estimate itself. We cover the import fees line on Amazon in How to See Amazon Prices in Another Country.

Record schema

Each measurement is one row: one source, one destination address, one basket. The code below writes the measurement plan to an empty CSV. The result columns fill up as measurements run.

python
import csv
import itertools
from datetime import datetime, timezone

targets = [("DE", "10115"), ("FR", "75001"), ("US", "02108"), ("GB", "SW1A 1AA")]
baskets = {"S1": 1, "S3": 3}  # same product, below and above the threshold
sources = ["carrier_api", "store_cart"]

fields = ["time", "source", "country", "postal_code", "basket", "ip_country",
          "currency", "subtotal", "shipping", "duty", "tax",
          "tax_paid_at", "delivery_time", "raw_response_digest"]

with open("measurements.csv", "w", newline="", encoding="utf-8") as f:
    writer = csv.DictWriter(f, fieldnames=fields)
    writer.writeheader()
    for source, (country, pc), basket in itertools.product(sources, targets, baskets):
        writer.writerow({"time": datetime.now(timezone.utc).isoformat(timespec="seconds"),
                         "source": source, "country": country, "postal_code": pc, "basket": basket})

Two sources, four addresses and two baskets give a 16-row plan. The reasoning behind a few fields:

FieldWhy
time (UTC)Separates exchange-rate and promotion changes
ip_countryProves that address and IP match
currencyA price number alone means nothing
tax_paid_atAt checkout or on delivery
raw_response_digestA digest of the response, for later disputes

Record the currency without converting it. Convert at comparison time, from a single rate source, at the rate of the measurement day. Keeping the raw response in a separate file and writing only its digest to the row keeps the table light.

Troubleshooting

When a result looks odd, the problem is usually in a step before the measurement.

  • The same address returned two different rates. The basket or the IP changed. Compare the ip_country and basket columns.
  • The price came back in the wrong currency. The store picked the currency from the IP. Check the country of the exit IP.
  • The destination country is missing from the shipping list. The store may restrict the list by IP country. If you're measuring the view of a customer in the destination country, pick an IP from that country.
  • The postal code join fails. The code turned into a number and lost the zero at its start. Read the file with dtype.
  • The cart emptied between steps. The IP changed mid-flow. Run the flow in a single sticky session.
  • Free shipping didn't kick in at the expected amount. The threshold looks at the taxed or discounted amount. Record the subtotal and the threshold's basis together.

How we tested

We ran the code examples locally on December 3, 2026, with Python 3.13.17 and pandas 3.1.2. The volumetric weight function gave the two outputs above. The plan script produced a 16-row CSV. We tested the postal code behavior with two separate files: one with digit-only codes and one with a UK postcode. The sample postal codes in this post are real, but we didn't measure any shipping price and give no figures.

The bottom line

Start with the carrier API, continue with the store's shipping table, and use the cart calculator only for the gaps that remain. Keep the basket fixed, store postal codes as text and write taxes to separate columns. Above all, record the IP country: without that column you can't spot a measurement taken in the wrong country. Use cases for teams that measure prices regularly are on our price monitoring page.

Sources

Frequently asked questions

Where do you collect shipping rate data from?

From the carriers' official rate APIs first. These APIs return a price per service based on address, weight and dimensions, but they require an account and show your contracted rates. For the rate a store charges its customers, look at the store's shipping page, and at the cart calculator for cases the page doesn't cover. Don't create orders, and follow the site's terms.

How is volumetric weight calculated?

Multiply the box's length, width and height and divide by the divisor the carrier publishes. The carrier charges for the larger of the actual and volumetric weight. The divisor and rounding rule vary by carrier, so take both from the carrier's documentation. With this calculation, a light but large box is priced like a heavy parcel. Keep the box size fixed in the test basket too.

How do you measure a free-shipping threshold?

With two baskets. Pick two quantities of the same product that sit just below and just above the threshold, so the only difference is the quantity. Also record which amount the threshold looks at: the subtotal before discounts, the discounted amount or the total with tax. Don't use a promo code while measuring, as it can lower the threshold.

Does the IP address or the delivery address set the shipping rate?

The delivery address. The rate is calculated from the destination country and postal code. The IP affects the currency, the language version, the estimated shipping on the product page and sometimes the list of countries the store ships to. To measure the total a local customer sees, the IP country and delivery country must match. Record the IP country in every row.

Why should postal codes be stored as text?

To keep codes intact. US codes such as 02108 start with a zero and become 2108 when converted to a number. In our test, pandas turned the column into numbers when it held only digit codes. Once a UK postcode was added, it left the column as text. When reading the file, declare the postal code column as text with dtype.

Are duties and taxes included in the shipping rate?

It depends on the store. Some stores collect taxes at checkout, at others the customer pays them on delivery. Write shipping, duty and tax to separate columns and record where the tax is collected. Don't calculate taxes yourself. The carrier's duty estimate service returns the estimate from the HS code. Tax paid on delivery doesn't appear on the checkout page.

Ask ChatGPTAsk Claude