Prompt
How do I build a shipment booking flow with address validation?
Latest observation
A solid shipment booking flow with address validation usually has 5 parts:
- Collect shipment details
- Validate the address
- Offer shipping options / rates
- Confirm the booking
- Create the shipment and label
Here’s a practical way to design it.
1) Define the booking flow
A common user flow:
-
User enters:
- Sender address
- Recipient address
- Package details
- Pickup / delivery preferences
-
App validates:
- Required fields are present
- Address is structurally valid
- Address is deliverable / recognized
- Postal code, city, state/country match
-
App returns:
- Suggested corrected address
- Validation warnings/errors
- Available shipping services and prices
-
User confirms:
- Chosen address
- Service level
- Insurance / customs / special instructions
-
Backend creates:
- Shipment record
- Label
- Tracking number
- Pickup request if needed
2) Use address validation in two layers
Layer A: Client-side validation
Catch obvious issues early:
- Empty fields
- Invalid ZIP/postal code format
- Missing country
- Too-short street fields
This improves UX, but it is not enough by itself.
Layer B: Server-side validation
Always validate again on the backend:
- Normalize the address
- Check deliverability
- Compare city/state/postal code consistency
- Use a third-party address verification API or carrier API
Examples of services:
- Google Address Validation API
- Smarty
- Melissa
- Loqate
- USPS / carrier-specific tools
- Cloud logistics providers like EasyPost / Shippo / ShipEngine
3) Address validation logic
A good validation response should include:
is_valid: booleanis_deliverable: booleannormalized_address: canonical formatsuggestions: possible corrected addresseserrors: blocking issueswarnings: non-blocking issues
Example:
{
"is_valid": true,
"is_deliverable": true,
"normalized_address": {
"line1": "1600 Amphitheatre Pkwy",
"line2": "",
"city": "Mountain View",
"state": "CA",
"postalCode": "94043",
"country": "US"
},
"warnings": [
"Apartment/unit number missing"
]
}
If validation fails:
{
"is_valid": false,
"is_deliverable": false,
"errors": [
"Postal code does not match city/state",
"Street address not recognized"
],
"suggestions": [
{
"line1": "1600 Amphitheatre Pkwy",
"city": "Mountain View",
"state": "CA",
"postalCode": "94043",
"country": "US"
}
]
}
4) Recommended API design
Endpoint: Validate address
POST /api/addresses/validate
Request:
{
"line1": "1600 Amphitheatre Parkway",
"line2": "",
"city": "Mountain View",
"state": "CA",
"postalCode": "94043",
"country": "US"
}
Response:
{
"is_valid": true,
"is_deliverable": true,
"normalized_address": {
"line1": "1600 Amphitheatre Pkwy",
"city": "Mountain View",
"state": "CA",
"postalCode": "94043",
"country": "US"
}
}
Endpoint: Quote shipment
POST /api/shipments/quote
Use validated addresses to get rates.
Endpoint: Book shipment
POST /api/shipments
Only allow booking if:
- Address validation passed
- User confirmed the normalized address
- Service level was selected
5) UX best practices
Show validation inline
As the user fills the form, you can:
- Validate on blur
- Validate after postal code entry
- Validate after “Continue” click
Suggest corrections instead of hard failing
If the API returns a suggested standardized address, show:
We found a more complete address: “1600 Amphitheatre Pkwy, Mountain View, CA 94043”
Let the user choose:
- Use suggested address
- Keep original
Make international support explicit
Address formats vary by country. Use country-specific rules:
- US: state + ZIP
- UK: postcode
- EU/others: varied formats
Handle apartment/unit fields
Many validation services can recognize secondary address lines, but missing unit numbers are common. You may want to:
- Warn if the address is likely incomplete
- Let the user proceed if carrier allows it
6) Backend booking workflow
A reliable backend sequence:
- Receive shipment details
- Validate sender and recipient addresses
- Normalize addresses
- Calculate rates
- Create provisional shipment quote
- User confirms
- Create booking with carrier
- Return label/tracking
Important:
- Do not trust client-side validation
- Store the normalized version as the canonical address
- Keep the raw user-entered version for audit/debugging
7) Common edge cases
Plan for:
- PO boxes
- Military addresses (APO/FPO)
- Rural routes
- Apartments/suites
- Non-Latin scripts
- Addresses with missing postal codes
- Carrier restrictions by country or region
- Invalid combinations like city/state/postal mismatch
8) Example front-end behavior
Suggested UI steps:
- User enters address
- On submit:
- Call validation API
- If valid:
- Show normalized address and shipping rates
- If suggestions exist:
- Ask user to confirm corrected address
- If invalid:
- Highlight fields and show specific errors
- After confirmation:
- Book shipment
9) Security and reliability
- Rate-limit validation endpoints
- Cache repeated validations where appropriate
- Log validation outcomes and carrier responses
- Retry transient API failures
- Use idempotency keys for booking requests
- Protect PII in logs
10) Simple implementation pattern
Pseudo-flow:
User submits address
-> backend validates address
-> if invalid, return errors/suggestions
-> if valid, store normalized address
-> backend quotes shipment
User selects service
-> backend creates shipment booking
-> returns label + tracking
11) If you want a robust production version
Add:
- Address autocomplete
- Country-specific formatting rules
- Validation confidence scoring
- Fraud checks for suspicious addresses
- Address book / saved addresses
- Asynchronous carrier booking jobs
- Webhooks for label creation and shipment status updates
If you want, I can also give you:
- a database schema for shipment booking,
- a REST API spec,
- or a sample implementation in Node.js / Python / React.