# Charter whole or part of a transport - Affrètement

Operations you have to perform to handle chartering.

Tip: it is easier to deal with many transports when you store their Dashdoc uid in you system. Transport uid is given in the reponse of the transport creation endoint.

## Creating chartered transports (no break, A→B)

* 1. create the transport with no information about chartering first
  2. `POST` on `/api/v4/transports/`
* 1. call the charter API to charter the transport or the segment (equivalent for a simple transport)
  2. `POST` on `/api/v4/transports/<transport_uid>/charter/`
  3. or `POST` on `/api/v4/segments/charter/?uid__in=<segment_uid>`

```
{
    "carrier": {"pk": 123}, // or {"remote_id": "ABC123"}
    "instructions": "text"
}
```

### Push license plates to the child transport

Not possible, use chartering instructions which will be saved in the child transport general instructions.

## Deleting/cancelling chartered transports

‌Cancel the parent transport.

`POST` on `/api/v4/transports/<transport_uid>/cancel/`

This will also cancel all chartered (children) transports.

## Updating chartered transports

### Update non-structural information (date, times, loading/unloading addresses, instructions, loads)‌

`PATCH` on `/api/v4/transports/<transport_uid>/`

or `PATCH` on `/api/v4/segments/<segment_uid>/`

The updated information flows down to the child transport

### Update the license plates

`PATCH` on `/api/v4/transports/<transport_uid>/charter/`

or `PATCH` on `/api/v4/segments/<segment_uid>/charter`

with

```
{
    "instructions": "New instructions"
}
```

### Change the structure of the transport (e.g. A→B to A→B→C)

Cancel the transport (this will also cancel the child transport) and re-create a new transport, then charter it according to the new transport structure.

If structure is changed on a chartered transport, Dashdoc API returns an error.

## Changing the chartered carrier

### Changing the chartered carrier

1. on chartered transport
   1. `DELETE` on `/api/v4/transport/<transport_uid>/charter/` No payload required.\
      This will cancel the child transport.
   2. `POST` on `/api/v4/transports/<transports_uid>/charter/` with the new carrier information. This will create a new chartered transport.
2. on chartered segment
   1. `DELETE` on `/api/v4/segments/charter/?uid__in=<segment_uid>` No payload required.\
      This will cancel the child transport.
   2. `POST` on `/api/v4/segments/charter/?uid__in=<segment_uid>` with the new carrier information. This will create a new chartered transport.

### Go from a chartered transport to a transport carried by you

1. On chartered transport
   1. `DELETE` on `/api/v4/transport/<transport_uid>/charter/` No payload required.\
      This will cancel the child transport.
   2. Call `POST` on `/api/v4/transports/<transport_uid>/assign/` with the id of the trucker.
2. On chartered segment
   1. `DELETE` on `/api/v4/segments/charter/?uid__in=<segment_uid>` No payload required.\
      This will cancel the child transport.
   2. Call `PATCH` on `/api/v4/segments/<segment_uid>/` with trucker info.

### Go from a transport carried by you to a chartered transport

‌`POST` on `/api/v4/transports/<transport_uid>/charter/` with the id of the carrier.

or `POST` on `/api/v4/segments/charter/?uid__in=<segment_uid>` with the id of the carrier.

It will unassign your truckers from the chartered segments.

## Complex transports

### Create a transport with one part with a trucker and the second part chartered

Create a complex transport with 2 segments.

1. Call `PATCH` on `/api/v4/segments/<segment_1_uid>/` with trucker info
2. Call `POST` on `/api/v4/segments/charter/?uid__in=<segment_2_uid>` with the id of the carrier

### Create a transport with 2 different chartered carriers

Create a complex transport with 2 segments.

1. Call `POST` on `/api/v4/segments/charter/?uid__in=<segment_1_uid>` with the id of carrier 1
2. Call `POST` on `/api/v4/segments/charter/?uid__in=<segment_2_uid>` with the id of carrier 2

### Create a transport with several segments chartered to another carrier

Create a complex transports where all segments are not assigned to the same carrier and at least two segments are chartered to another carrier.

Example: A→B →C →D where :

* A → B is assigned to a trucker
* B →C and C → D are chartered to another carrier

1. call `POST` on `/api/v4/segments/charter/?uid__in=uid_B-C,uid_C-D`

The API controls that segments are from the same transport and exist in this order.

In this case the number of chartered segments is unlimited and may occur anywhere in the list of segments from the original transport.
