# Flow Diagrams

The main flow diagrams can be found here for implementation guidance.

# Parcel Booking Flow

![Parcel booking flow: optional pre-check, booking, and the booking webhook](/diagrams/parcel-booking-flow.svg)

**1. Pre-check (optional).** The `PRE_CHECK` step checks if a parcel can be reserved in a specific locker. It does not reserve a compartment.

Example usage: the parcel is created, but delivery is still a few days away. `PRE_CHECK` shows if the parcel must be redirected. It checks the maximum size and the parcel details, for example the locker ID.

**2. Booking.** API reference: [Publish parcel data](/api/parcel-api#publish-parcel-data).

```json
{
  "eventType": "BOOKING",
  "lockerUid": "someLockerUid",
  "carrierParcelId": "someCarrierParcelId",
  "consignee": {
    "name": "John Doe",
    "email": "john.doe@example.com"
  },
  "dimensions": {
    "depth": 42,
    "height": 42,
    "width": 42
  },
  "weight": 42
}
```

The result arrives asynchronously over the parcel webhook. API reference: [Webhook for parcel updates](/webhooks-api/parcel-events#webhook-for-parcel-updates).

```json
{
  "shipmentUid": "anyParcelId123",
  "lockerUid": "anyLockerId123",
  "carrierParcelId": "anyCarrierParcelId123",
  "carrierLockerId": "Locker1",
  "shipmentType": "LAST_MILE",
  "shipmentStatus": "CREATED",
  "accessCodes": {
    "consigneeCollection": "compartmentAccessCode123"
  },
  "events": [
    {
      "timestamp": "2024-05-04T09:42:00+00:00",
      "eventType": "BOOKING_CREATED"
    }
  ]
}
```

# Parcel Cancel Flow

![Parcel cancel flow: cancel succeeds before delivery and fails after delivery](/diagrams/parcel-cancel-flow.svg)

A parcel delivery can be cancelled only before the parcel is delivered into the locker. API reference: [Cancel parcel](/api/parcel-api#cancel-parcel).

# Courier Collection/Delivery Flow

![Courier collection and delivery flow: Courier App integration, Collection webhook, and parcel webhooks](/diagrams/courier-collection-delivery-flow.svg)

This flow is the same for all locker types, and for both collection and delivery. For delivery into lockers with a screen and a barcode reader, the courier does not need a *Courier Delivery Access Code*: the courier scans the parcel, and the compartment booked for the parcel opens.

The response to `POST /app/courier/lockers/{lockerUid}` contains the courier session data, for example the locker access codes and the parcels to deliver and collect.

The Collection webhook body:

```json
{
  "lockerUid": "string",
  "courierAccessCode": "string",
  "parcels": [
    {
      "carrierParcelId": "string"
    }
  ]
}
```
