Shiprocket Integration — Serviceability & Shipping Tiers
shipment-service’s ShipmentInfoService.GetServiceability never hands Shiprocket’s raw courier list to a caller — it runs it through a fixed pipeline and reduces it to at most two selectable options, STANDARD and EXPRESS. This page is the pipeline, field by field.
Why not just show every courier?
Shiprocket’s serviceability endpoint can return a dozen or more couriers for a single pincode pair, several of them blocked, rate-limited, or simply poor options. Surfacing that list directly would turn checkout into a courier-selection screen instead of a shipping-speed choice — the platform’s own STANDARD/EXPRESS framing exists specifically so the customer never has to reason about carrier names.
Step 1 — pre-filter
A courier entry from Shiprocket’s response is discarded if any of the following is true:
blocked === 1orsuppressed === 1rate <= 0oretd_hours <= 0rating < 3.0(defaults to passing whenratingis absent — don’t let a missing rating silently exclude a courier)
If the filtered list is empty, GetServiceability returns no tiers at all rather than falling back to an unfiltered list.
Step 2 — pick the Standard and Express candidates
- Standard candidate — the lowest
ratein the filtered list. A tie breaks toward the loweretd_hours. - Express candidate — the lowest
etd_hoursin the filtered list. A tie breaks toward the lowerrate.
These two picks can land on the same courier — that’s expected and handled in Step 3.
Step 3 — decide whether Express is worth showing
Express is only exposed if it is genuinely faster than Standard: expressCandidate.etd_hours < standardCandidate.etd_hours, and it resolved to a different courier. If the “fastest” courier isn’t actually faster than the “cheapest” one — same ETD, just a different price — showing it as a distinct option would be a higher price with no speed benefit, which erodes trust at checkout more than it helps. In that case only STANDARD is returned.
Reference implementation
The following is the actual filter/select logic (Go in production; shown here in the original JS it was ported from, since the shape reads more compactly):
interface ShiprocketCourierPayload {
courier_company_id: number;
courier_name: string;
rate: number;
etd_hours: number;
estimated_delivery_days: string;
rating?: number;
blocked?: number;
suppressed?: number;
}
interface ShippingTierOption {
id: "STANDARD" | "EXPRESS";
title: string;
price: number;
estimated_days: string;
internal_courier_id: number;
fallback_courier_ids: number[];
}
function buildShippingTiers(couriers: ShiprocketCourierPayload[]): ShippingTierOption[] {
const valid = (couriers || []).filter((c) =>
(c.blocked ?? 0) === 0 &&
(c.suppressed ?? 0) === 0 &&
c.rate > 0 &&
c.etd_hours > 0 &&
(c.rating ?? 5) >= 3.0
);
if (valid.length === 0) return [];
const standard = valid.reduce((best, cur) =>
cur.rate < best.rate || (cur.rate === best.rate && cur.etd_hours < best.etd_hours) ? cur : best
);
const express = valid.reduce((best, cur) =>
cur.etd_hours < best.etd_hours || (cur.etd_hours === best.etd_hours && cur.rate < best.rate) ? cur : best
);
const fallbacksFor = (sortKey: (c: ShiprocketCourierPayload) => number, exclude: number) =>
[...valid].sort((a, b) => sortKey(a) - sortKey(b))
.map((c) => c.courier_company_id)
.filter((id) => id !== exclude);
const options: ShippingTierOption[] = [{
id: "STANDARD",
title: "Standard Delivery",
price: standard.rate,
estimated_days: `${standard.estimated_delivery_days} Days`,
internal_courier_id: standard.courier_company_id,
fallback_courier_ids: fallbacksFor((c) => c.rate, standard.courier_company_id),
}];
const isFaster = express.etd_hours < standard.etd_hours;
const isDifferentCourier = express.courier_company_id !== standard.courier_company_id;
if (isFaster && isDifferentCourier) {
options.push({
id: "EXPRESS",
title: "Express Delivery",
price: express.rate,
estimated_days: `${express.estimated_delivery_days} Days`,
internal_courier_id: express.courier_company_id,
fallback_courier_ids: fallbacksFor((c) => c.etd_hours, express.courier_company_id),
});
}
return options;
}
Each tier carries internal_courier_id plus an ordered fallback_courier_ids list — this is what assignAWBWithFallback (see the fulfillment API reference) retries through if the primary courier’s AWB assignment fails.
Multi-item orders: aggregating into one package
Shiprocket’s serviceability call takes a single overall weight and a single set of dimensions — it is never called once per item. Before the call:
- Total weight (kg) =
Σ(item.weight_g × item.quantity) / 1000. - Dimensions — max length and width across all items (max-footprint), and the sum of
height × quantityacross all items (stacked height). A fixed-box-size packing strategy, if the business adopts one, would map the aggregate instead of computing it from item dimensions.
Caching strategy
Serviceability results are cached because a Shiprocket call costs ~600ms and courier rates don’t change within the span of a shopping session, but the response does depend on origin, destination, weight, and payment type — so the cache key has to carry all of those or two unrelated carts will collide on a stale answer.
Cache key format: shiprocket:serviceability:{origin_pincode}:{delivery_pincode}:{weight_group}:{is_cod}
origin_pincode/delivery_pincode— the warehouse pickup pincode and the customer’s delivery pincode.weight_group— the aggregate weight rounded up to a fixed step (e.g. 0.5kg increments), so near-identical carts share a cache entry instead of each landing on its own key.is_cod—1/0; Shiprocket’s rates and serviceability genuinely differ between COD and prepaid.
TTL — 1–4 hours balances a high hit rate against rate/zone drift; a longer TTL (24h) is only safe for a low-volume catalog where courier rates and operational zones rarely change. shipment-service’s own shipment_info collection mirrors this with a 1-hour TTL index.
A real serviceability response, for shape reference
{
"currency": "INR",
"data": {
"available_courier_companies": [
{
"courier_company_id": 43,
"courier_name": "Delhivery Surface",
"rate": 54,
"etd_hours": 91,
"estimated_delivery_days": "4",
"rating": 4.9,
"blocked": 0,
"cod": 1,
"is_surface": true
},
{
"courier_company_id": 19,
"courier_name": "Ecom Express Surface 2kg",
"rate": 150.12,
"etd_hours": 144,
"estimated_delivery_days": "6",
"rating": 4.62,
"blocked": 0,
"cod": 1,
"is_surface": true
}
],
"blocked_courier_companies": [
{ "courier_company_id": 33, "courier_name": "Xpressbees Air", "block_reason": "Operational Issues" }
],
"recommended_courier_company_id": 43
},
"status": 200
}
Trimmed to the fields the tier-selection algorithm actually reads — the live payload carries several dozen more per courier (pickup/delivery performance scores, zone codes, suppression windows), none of which feed buildShippingTiers.
Related Documents
- Hub — Shiprocket Integration
- Fulfillment API Reference — next step: how the selected tier’s
internal_courier_id/fallback_courier_idsfeedAssignAWB - Architecture: Multi-Courier Fulfillment via Shiprocket — flow (A)
- shipment-service