Skip to content

Show a dispatch estimate at checkout

Use your order cutoff, business time zone, and public holiday calendar to show when preparation should finish.

Working example

ParseAPI
Node

Set up ParseAPI

Set PARSEAPI_KEY in your server environment. Use Node.js 22 or later.

Terminal
export PARSEAPI_KEY='YOUR_SECRET_API_KEY'
Get an API key ↗

Give checkout a useful dispatch date

Show when an order should finish preparation before the customer commits. Combine your business's processing time and cutoff with the Holiday API, then place the estimated dispatch date beside the checkout choice.

This example prepares orders Monday-Friday in America/New_York, excluding US federal public holidays and December 24, 2026. Standard preparation takes two business days; Priority takes one. A working day counts as day one only when the order arrives before 2pm. At 2pm or later, counting begins on the next working day.

Dispatch means preparation has finished. It does not estimate carrier transit or promise an arrival date.

1. Map a checkout choice to your preparation policy

The form lets the customer choose a service:

JavaScript
const form = `<section class="account"><h2>Your basket</h2><p>Studio notebook · Quantity 1</p></section>
<form method="post" action="/">
  <label for="service">Order preparation</label>
  <select id="service" name="service" aria-describedby="policy">
    <option value="standard"${fields.service !== 'priority' ? ' selected' : ''}>
      Standard - 2 business days
    </option>
    <option value="priority"${fields.service === 'priority' ? ' selected' : ''}>
      Priority - 1 business day
    </option>
  </select>
  <p id="policy" class="note">A working day before 2pm counts as day one.
    Weekends, US federal holidays, and December 24, 2026 are closed.</p>
  <button type="submit">Estimate dispatch</button>
</form>`;

The server maps standard and priority to its own processing durations. It also takes the order time from its own clock. The customer supplies neither an arbitrary processing time nor a timestamp that could move the cutoff.

Use your existing checkout's cart and service selection in place of the sample basket. Keep cutoff, working week, time zone, and special closures in your trusted business policy.

2. Fetch each holiday year the estimate needs

The server requests GET /holiday/US?year=... with Node's built-in fetch. The secret key stays in a header, and X-API-Version: 2.3.0 selects the response contract:

JavaScript
const url = new URL(`/holiday/${encodeURIComponent(country)}`, 'https://api.parseapi.com');
url.searchParams.set('year', String(year));
const timeout = AbortSignal.timeout(8000);
const response = await fetcher(url, {
  headers: { 'X-API-Key': apiKey.trim(), 'X-API-Version': '2.3.0' },
  signal: signal ? AbortSignal.any([signal, timeout]) : timeout,
  redirect: 'error',
});
if (!response.ok) throw new Error('The holiday calendar could not be checked.');
const calendar = await response.json();

The small createClient function makes one attempt per calendar, with an eight-second deadline and the calculation's cancellation signal. It leaves the business calculation injectable for tests.

The response's country and year must match the calculation. Keep public holidays as a set of dates:

JavaScript
const holidays = new Set(calendar.holidays
  .filter(holiday => holiday.type === 'public')
  .map(holiday => holiday.date));

Observances do not close this business. Duplicate names on one date still remove only one day, and published substitute dates stay where they are. The complete source rejects malformed calendars and unexpected regional scope.

December orders may need the next year's calendar. Load each reached year once per estimate. If a required year is unavailable, show an unavailable estimate rather than treating its holidays as working days.

3. Count dates in the business calendar

Node's Intl.DateTimeFormat converts the server's current instant into the known business time zone. An additional Time API call is unnecessary when the runtime already has that zone.

Use whole UTC day numbers only to advance civil dates. The order's local date and clock still come from America/New_York, so a daylight-saving change does not turn a 24-hour step into the wrong date.

JavaScript
const weekday = ![0, 6].includes(new Date(day * DAY).getUTCDay());
const working = weekday && !calendars.get(year).has(date)
  && !POLICY.closedDates.includes(date);
const beforeCutoff = day !== start || clock.minutes < POLICY.cutoffMinutes;
if (working && beforeCutoff && --remaining === 0) {
  return {
    date, orderDate: clock.date, service: SERVICES[service].label,
    processingDays: SERVICES[service].days
  };
}

For Standard preparation, a working Monday at 1:59pm counts Monday and Tuesday. The same order at 2pm starts counting Tuesday and finishes Wednesday, provided those dates are open.

4. Put the estimate beside the order choice

The server's result becomes the checkout message:

JavaScript
return `<section class="result"><h2>Estimated dispatch:
  <time datetime="${escape(estimate.date)}">${escape(estimate.date)}</time></h2>
  <p>${escape(estimate.service)} preparation, ${estimate.processingDays}
    business ${estimate.processingDays === 1 ? 'day' : 'days'}.</p>
  <p class="note">Based on the server's order time in America/New_York.
    Dispatch is when preparation finishes, not the arrival date.</p></section>`;

Recalculate using the actual receipt time when your existing order handler accepts the order. An estimate shown before the cutoff may change if checkout completes afterward. Store the applied policy with an accepted fulfillment commitment in your own order system.

The standalone app renders the estimate and stores no orders. Changing the preparation choice clears the old result and cancels any pending calculation. Request failures leave the form available to retry.

See the Holiday reference for calendar coverage. For selecting an appointment date instead, recheck a booking date.

Complete example

Use the complete implementation as a reference when adding this feature to your app. It includes the validation and failure handling around the calls above.

View and copy the complete source
Try the complete example on your computer

After completing the setup above, save the source in your application folder and start the app:

Terminal
node checkout-dispatch-date.node.mjs

Open 127.0.0.1:8000 to use the form. The server keeps your secret key out of the page.

For every field and parameter, see Holiday API reference.

Build something else

All tutorials →