Prompt
How do I build shipping rate shopping across carriers?
Latest observation
To build shipping rate shopping across carriers, you’re basically creating a system that asks multiple shipping providers, compares options, and selects the best one for a given package/order.
1) Decide what “best” means
Before integrating carriers, define your optimization rules. Common goals:
- Lowest cost
- Fastest delivery
- Best cost-to-speed balance
- Cheapest among carriers that meet a delivery promise
- Exclude carriers by zone, service level, package size, or destination
You may also need business rules like:
- Never use carrier X for international shipments
- Prefer carrier Y for residential deliveries
- Use only services that support Saturday delivery
- Avoid carriers with poor performance for certain regions
2) Normalize shipment data
Your rate-shopping layer should accept a standardized shipment object, e.g.:
- Origin address
- Destination address
- Package weight
- Dimensions
- Package count / multi-piece shipment
- Declared value / insurance
- Signature required
- Customs info for international
- Delivery constraints (overnight, economy, etc.)
Then map that standard object to each carrier’s API format.
3) Integrate carrier APIs
Each carrier has different rate APIs, authentication, request formats, and service codes. Typical carriers include:
- UPS
- FedEx
- USPS
- DHL
- Regional/niche carriers
For each carrier, implement:
- Authentication
- Rate request building
- Response parsing
- Error handling
- Service normalization
Normalize returned rates
Carriers often use different labels for the same thing. Convert them into a common structure like:
{
"carrier": "UPS",
"service_code": "GROUND",
"service_name": "UPS Ground",
"total_price": 12.34,
"currency": "USD",
"estimated_delivery_date": "2026-01-10",
"transit_days": 4,
"fuel_surcharge": 1.25,
"delivery_guaranteed": false
}
4) Build a rate-shopping engine
The engine should:
- Receive shipment details
- Determine eligible carriers/services
- Call carrier rate APIs
- Normalize all responses
- Rank results using your rules
- Return one or more recommended options
Ranking examples
- Sort by lowest total price
- Filter out options slower than X days
- Prefer guaranteed delivery if within 10% of cheapest
- Penalize carriers with poor historical performance
5) Handle real-world rate complexities
Shipping rates are rarely simple. Account for:
- Residential vs commercial
- Dimensional weight
- Fuel surcharges
- Remote area surcharges
- Peak season surcharges
- Residential delivery fees
- Signature/insurance fees
- Liftgate or special handling
- Accessorials
- Zone-based pricing
- International duties/taxes
- Minimum charges and rounding rules
If you don’t model these correctly, your “cheapest” rate may not actually be cheapest.
6) Consider caching and latency
Calling multiple carrier APIs for every checkout can be slow and expensive. Improve performance with:
- Cache rate quotes briefly for identical shipments
- Parallelize carrier requests
- Use timeouts and fail fast if one carrier is slow
- Fallback strategies when a carrier API is down
Example:
- Fire all carrier requests concurrently
- Wait up to 2–3 seconds
- Return available results, not necessarily all results
7) Use a fallback or aggregator
If you don’t want to integrate every carrier directly, you can use a shipping API aggregator such as:
- EasyPost
- Shippo
- ShipEngine
- Direct integration through a 3PL or WMS provider
These can simplify:
- Rate shopping
- Label creation
- Tracking
- Address validation
But direct integrations may give you more control and potentially better pricing.
8) Add address validation
Invalid or incomplete addresses can break rate requests or cause bad quotes. Validate:
- ZIP/postal code
- City/state match
- Residential/commercial classification
- International formatting
9) Build observability
Log and monitor:
- Carrier response times
- API failure rates
- Rate quote success rates
- Quote-to-label conversion
- Cost savings by carrier selection
- Delivery performance by carrier/service
This helps you tune the shopping logic over time.
10) Test with real-world scenarios
Test:
- Different package sizes and weights
- Domestic and international
- Residential and commercial
- Multi-package shipments
- PO boxes
- Remote destinations
- Heavy/larger-than-normal shipments
- Edge cases that trigger dimensional weight or surcharges
Example architecture
A simple design:
- Checkout / shipping quote UI
- Shipping service
- Rate shopping engine
- Carrier adapters (UPS/FedEx/USPS/etc.)
- Normalization layer
- Rules engine
- Cache
- Logging/metrics
Example flow
- Customer enters destination and package info.
- System validates address.
- Shipping service sends quote request to rate engine.
- Rate engine queries UPS/FedEx/USPS in parallel.
- Responses are normalized.
- Business rules filter and rank options.
- Best 3 rates are returned to the UI.
- User selects one, and you purchase the label from that carrier.
Practical tip
Start with these:
- 2–3 carriers
- A normalized rate schema
- Parallel API calls
- Basic ranking by total cost and transit time
Then expand to:
- Surcharges
- Historical performance-based optimization
- International support
- Label purchase and tracking
If you want, I can also give you:
- a sample system design,
- a database schema, or
- example code for a rate-shopping service in Node.js/Python/Java.