DEV Community

24hTrack
24hTrack

Posted on AI-assisted

Classify the route before you compute transit time

If you build anything on top of shipment tracking — a merchant dashboard, a WISMO deflection bot, an "average transit time" KPI — you will eventually compute a single number across all your shipments and then discover it means nothing. Not because the data is dirty, but because you averaged three different physical processes together.

Here is a cheap classifier that fixes it, built entirely out of the words carriers already put in the scan text.

The three vocabularies

Carrier scan text is written by operations people, not by a standards body, so it leaks the physics of the route. Bucket a history by which of these appears:

1. Station words — a domestic road network.

Nilai, Picked up by Courier
Nilai, Outbound from NLI station
Auto Hub, In Transit
Petaling Jaya, Inbound to PJY station
Petaling Jaya, Out for Delivery
Petaling Jaya, Delivered
Enter fullscreen mode Exit fullscreen mode

Match on outbound from .* station, inbound to .* station, hub. The three-letter codes are depot abbreviations.

2. Airline words — a cross-border air lane.

The shipment is being transshipped via the hub
Arrived at the origin international airport
International flight has departed
International flight has arrived
Customs clearance is in progress
Clearance processing completed - Import
Enter fullscreen mode Exit fullscreen mode

Another operator writes the same physics differently: Hand over to airline, Departed from origin port, Arrived at destination port, Customs clearance completed, in transit. Match on flight, airline, origin port, clearance.

3. Pallet / container words — sea freight.

已提板/提柜             pallet or container collected
拆板/拆柜完成,等待派送   deconsolidation complete, awaiting despatch
Enter fullscreen mode Exit fullscreen mode

Match on 提板|提柜|拆板|拆柜, deconsolidat, pallet, container.

Why the bucket matters more than the average

Measured end to end, between the carrier's own first scan and its own delivery scan, on parcels that actually completed:

bucket median p80
station words (domestic) 1 day 3 days
airline words (air export) 11 and 13 days on two separate services 19 and 25 days
container words (sea) 42 days 71 days

A blended "average transit time" across those three is a number that describes no shipment you have ever carried. Worse, it moves when your traffic mix moves, so your dashboard will show a "regression" the week a seller switches to sea freight.

Compute medians within bucket. Alert on a shipment only when it exceeds the p80 of its own bucket.

The silence is in a predictable place

This is the part that kills support tickets. Each bucket has a structural gap where nothing can be scanned:

  • Domestic: no structural gap. A week of silence is genuinely anomalous — surface it.
  • Air: between the departure line and the import clearance line. Nothing is scanned individually while a consolidated load is in the air or sitting in a customs queue. Silence after the clearance line is the one worth escalating.
  • Sea: between "container collected" and "deconsolidation complete". Weeks, by construction.

So "days since last scan" is not an alert signal on its own. "Days since last scan, where the last scan is not one of the known gap-openers for this bucket" is.

Two traps I walked into

Mixed buckets. A tracking-number prefix is not a route. Measuring one service, about 17 in 20 numbers matched its own format and the rest were other carriers' numbers a seller had pasted in — one of which was a postal chain through an entirely different pair of countries. Filter to the format that dominates the bucket before you compute anything, or your median inherits somebody else's route.

The handover flips the vocabulary mid-history. On roughly three in five of the US-bound shipments on one export service, the history stops speaking in the carrier's words and starts speaking in the destination post's — Pre-Shipment Info Sent to USPS, Accepted at USPS Facility, then named regional centres, then Delivered, In/At Mailbox. If you classify on the last few scans you will label a cross-border air lane as domestic. Classify on the whole history, weighted toward the earliest lines.

Bonus signal: place-name granularity

Independent of bucket, the specificity of the place name is a free progress bar. A facility named with a state or region code sorts for a whole area and a parcel may pass through two or three of them. The first time a scan names a town, the parcel has entered the last-mile network, and usually only arrived at local office, out for delivery, delivered remain.

Wide place names mean days. Narrow place names mean hours. That is a much better ETA hint than counting scans.


I work on 24hTrack, a free package tracker for 3,200+ carriers — paste any tracking number, the carrier is detected automatically, no sign-up. The numbers above are medians and percentiles measured on delivered parcels, not service-level promises. Written with AI assistance.

Top comments (0)