# Sequenced Availability

> **BETA**

Scheduling a simple set of events is simply a case of making a sequence with the steps defined in the desired order.

For example scheduling 2 sequential events of 30 minutes each for a given account:

```json
[
    {
      "sequence_id":"First Event",
      "ordinal":1,
      "participants":[{
          "members":[{ "sub": "acc_5ba21743f408617d1269ea1e" }],
          "required":"all"
      }],
      "required_duration":{ "minutes": 30 }
    },
    {
      "sequence_id":"Second Event",
      "ordinal":2,
      "participants":[{
          "members":[{ "sub": "acc_5ba21743f408617d1269ea1e" }],
          "required":"all"
      }],
      "required_duration":{ "minutes": 30 }
    }
]
```

The scheduling engine will determine a number of possible times this sequence of events can occur in.

For example it may be possible to schedule the events with each starting as the previous has finished.

<table class="schedule_table_long">
    <tr>
        <td rowspan="2" class="heading">9</td>
        <td> </td>
        <td class="new_event">First Event</td>
    </tr>
    <tr>
        <td> </td>
        <td class="new_event">Second Event</td>
    </tr>
    <tr>
        <td rowspan="2" class="heading">10</td>
        <td class="busy" rowspan="2">Busy Period</td>
        <td> </td>
    </tr>
    <tr>
        <td> </td>
    </tr>
</table>
Or it may be required that we schedule around an existing event in order to fit the events into the available period.

<table class="schedule_table_long">
    <tr>
        <td rowspan="2" class="heading">9</td>
        <td> </td>
        <td> </td>
    </tr>
    <tr>
        <td> </td>
        <td class="new_event">First Event</td>
    </tr>
    <tr>
        <td rowspan="2" class="heading">10</td>
        <td class="busy" rowspan="2">Busy Period</td>
        <td> </td>
    </tr>
    <tr>
        <td> </td>
    </tr>
    <tr>
        <td rowspan="2" class="heading">11</td>
        <td> </td>
        <td class="new_event">Second Event</td>
    </tr>
    <tr>
        <td> </td>
        <td> </td>
    </tr>
</table>
## Buffers
In addition to creating a sequence we can also define a buffer time between each step of the sequence, for example before and after each step 30 minutes.

A request creating 2 events with buffer formed like so:

```json
[
    {
      "sequence_id":"First Event",
      "ordinal":1,
      "participants":[{
          "members":[{ "sub": "acc_5ba21743f408617d1269ea1e" }],
          "required":"all"
      }],
      "required_duration":{ "minutes": 30 },
      "buffer":{
        "before": { "minutes" : 30 },
        "after": { "minutes" : 30 }
      }
    },
    {
      "sequence_id":"Second Event",
      "ordinal":2,
      "participants":[{
          "members":[{ "sub": "acc_5ba21743f408617d1269ea1e" }],
          "required":"all"
      }],
      "required_duration":{ "minutes": 30 },
      "buffer":{
        "before": { "minutes" : 30 },
        "after": { "minutes" : 30 }
      }
    }
]
```

Its important to note that although both the first and second steps have before and after buffers these are collapsed into one when the events are sequential.

<table class="schedule_table_long">
    <tr>
        <td rowspan="2" class="heading">9</td>
        <td class="buffer">Before buffer</td>
        <td> </td>
    </tr>
    <tr>
        <td class="new_event">First Event</td>
        <td> </td>
    </tr>
    <tr>
        <td rowspan="2" class="heading">10</td>
        <td class="buffer">After buffer</td>
        <td class="buffer">Before buffer</td>
    </tr>
    <tr>
        <td> </td>
        <td class="new_event">Second Event</td>
    </tr>
    <tr>
        <td rowspan="2" class="heading">11</td>
        <td> </td>
        <td class="buffer">After buffer</td>
    </tr>
    <tr>
        <td> </td>
        <td> </td>
    </tr>
</table>
However if the events are separated by a busy period both buffers will still be honoured.

<table class="schedule_table_long">
    <tr>
        <td rowspan="2" class="heading">9</td>
        <td> </td>
        <td class="buffer">Before buffer</td>
    </tr>
    <tr>
        <td> </td>
        <td class="new_event">First Event</td>
    </tr>
    <tr>
        <td rowspan="2" class="heading">10</td>
        <td> </td>
        <td class="buffer">After buffer</td>
    </tr>
    <tr>
        <td class="busy">Busy Period</td>
        <td> </td>
    </tr>
    <tr>
        <td rowspan="2" class="heading">11</td>
        <td> </td>
        <td class="buffer">Before buffer</td>
    </tr>
    <tr>
        <td> </td>
        <td class="new_event">Second Event</td>
    </tr>
    <tr>
        <td rowspan="2" class="heading">12</td>
        <td> </td>
        <td class="buffer">After buffer</td>
    </tr>
    <tr>
        <td> </td>
        <td> </td>
    </tr>
</table>
## Maximum buffer
We can also define buffers which have a maximum value associated with them, this is useful when generating a sequence to constrain the total time a sequence can occupy.

For example defining a buffer with a minimum of 30 minutes and a maximum of 60 will allow a buffer of between 30 and 60 minutes between each sequence step

We can change our previous example to add in this constraint:

```json
[
    {
      "sequence_id": "First Event",
      "ordinal": 1,
      "participants": [{
          "members":[{ "sub": "acc_5ba21743f408617d1269ea1e" }],
          "required":"all"
      }],
      "required_duration": { "minutes": 30 },
      "buffer": {
        "after": {
          "maximum": { "minutes" : 60 }
        }
      }
    },
    {
      "sequence_id": "Second Event",
      "ordinal": 2,
      "participants": [{
          "members":[{ "sub": "acc_5ba21743f408617d1269ea1e" }],
          "required":"all"
      }],
      "required_duration": { "minutes": 30 }
    }
]
```

This request means it is possible to generate a sequence with a 30 minute
busy period in between as this is within the maximum buffer.

<table class="schedule_table_long single_column">
    <tr>
        <td rowspan="2" class="heading">9</td>
        <td class="new_event">First Event</td>
    </tr>
    <tr>
        <td class="busy">Busy Period</td>
    </tr>
    <tr>
        <td rowspan="2" class="heading">10</td>
        <td class="new_event">Second Event</td>
    </tr>
    <tr>
        <td> </td>
    </tr>
</table>
However if the busy period is longer than 30 minutes we will exceed the maximum
buffer so the following example is not valid as the maximum buffer will be exceeded.

<table class="schedule_table_long single_column">
    <tr>
        <td rowspan="2" class="heading">9</td>
        <td class="new_event">First Event</td>
    </tr>
    <tr>
        <td class="busy" rowspan="3">Busy Period</td>
    </tr>
    <tr>
        <td rowspan="2" class="heading">10</td>
    </tr>
    <tr>
    </tr>
    <tr>
        <td rowspan="2" class="heading">11</td>
        <td class="new_event">Second Event</td>
    </tr>
    <tr>
        <td> </td>
    </tr>
</table>
## Start Intervals
Start intervals can also be used in a sequencing request, these are applied at each step to define when the step can start.

For example if two 30 minute steps have a 60 minute start interval this will create a minimum of a 30 minute gap between the events

```json
[
    {
      "sequence_id": "First Event",
      "ordinal": 1,
      "participants": [{
          "members":[{ "sub": "acc_5ba21743f408617d1269ea1e" }],
          "required":"all"
      }],
      "required_duration": { "minutes": 30 },
      "start_interval": { "minutes": 60 }
    },
    {
      "sequence_id": "Second Event",
      "ordinal": 2,
      "participants": [{
          "members":[{ "sub": "acc_5ba21743f408617d1269ea1e" }],
          "required":"all"
      }],
      "required_duration": { "minutes": 30 },
      "start_interval": { "minutes": 60 }
    }
]
```

Without a specifed start interval specified the sequence could be scheduled every 30 minutes.

<table class="schedule_table_long single_column">
    <tr>
        <td rowspan="2" class="heading">9</td>
        <td class="new_event">First Event</td>
    </tr>
    <tr>
        <td class="new_event">Second Event</td> </tr>
    <tr>
        <td rowspan="2" class="heading">10</td>
        <td> </td>
    </tr>
        <td> </td>
    <tr>
</table>
However adding a start interval of 60 minutes would mean a 30 minute gap is created between the steps.

<table class="schedule_table_long single_column">
    <tr>
        <td rowspan="2" class="heading">9</td>
        <td class="new_event">First Event</td>
    </tr>
    <tr>
        <td> </td>
    </tr>
    <tr>
        <td rowspan="2" class="heading">10</td>
        <td class="new_event">Second Event</td>
    </tr>
        <td> </td>
    <tr>
</table>
## Ordering
In the previous example we specified an order for events by setting the ordinial value for each step, this value is optional and
if omitted the ordinal is derived from position in the the array.

We also support the ability to specify a non-determined ordering of a sequence by which we mean the events can occur in any order.
We also allow this to be defined partially along with ordered events to define a soft ordering.

For example an interview sequence where we must have an introduction first but the Face to Face and Coding Exercise can occur
in any order.

```json
[
    {
      "sequence_id":"Introduction",
      "ordinal":1,
      "participants":[{
          "members":[{ "sub": "acc_5ba21743f408617d1269ea1e" }],
          "required":"all"
      }],
      "required_duration":{ "minutes": 30 }
    },
    {
      "sequence_id":"Face to Face",
      "ordinal":2,
      "participants":[{
          "members":[{ "sub": "acc_5ba21743f408617d1269ea1e" }],
          "required":"all"
      }],
      "required_duration":{ "minutes": 30 }
    },
    {
      "sequence_id":"Coding Exercise",
      "ordinal":2,
      "participants":[{
          "members":[{ "sub": "acc_5ba21743f408617d1269ea1e" }],
          "required":"all"
      }],
      "required_duration":{ "minutes": 30 }
    }
]
```

There are two possible orders this sequence can be generated in, the sequencing engine will consider each option to determine the best possible selection.

<table class="schedule_table_long single_column" style="float: left; margin-right: 50px">
    <tr>
        <td rowspan="2" class="heading">9</td>
        <td class="new_event">Introduction</td>
    </tr>
    <tr>
        <td class="new_event">Face to Face</td>
    </tr>
    <tr>
        <td class="heading" rowspan="2">10</td>
        <td class="new_event">Coding Execise</td>
    </tr>
    <tr>
        <td> </td>
    </tr>
</table>
<table class="schedule_table_long single_column">
    <tr>
        <td rowspan="2" class="heading">9</td>
        <td class="new_event">Introduction</td>
    </tr>
    <tr>
        <td class="new_event">Coding Execise</td>
    </tr>
    <tr>
        <td class="heading" rowspan="2">10</td>
        <td class="new_event">Face to Face</td>
    </tr>
    <tr>
        <td> </td>
    </tr>
</table>


---
[Read in HTML](/developers/scheduling/sequenced-availability/)