private void checkPossiblesTimeboxes(
      final Participant participant, List<TimeBox> possibleTbs, Priority priority) {

    if (possibleTbs.size() == 1) {

      boolean allocated = allocateTimeBox(possibleTbs.get(0), participant);
      if (allocated) return;
    }

    if (!possibleTbs.isEmpty()) {

      buffer.put(participant, Lists.newArrayList(possibleTbs));
      System.out.println("insert " + possibleTbs.size() + " timeboxes in the buffer");

      final Priority nextPriority = getNextPriority(priority);

      if (nextPriority != null) {

        System.out.println("set priority level to : " + nextPriority.getRole());

        // filter the unavaibilities to get only the ones matching the current priority level
        Collection<Unavailability> unavailabilities =
            Collections2.filter(
                this.unavailabilities,
                new Predicate<Unavailability>() {
                  public boolean apply(Unavailability a) {
                    Person p = a.getPerson();
                    return (p.equals(participant.getStudent())
                            || p.equals(participant.getFollowingTeacher()))
                        && (p.getRole() == nextPriority.getRole());
                  }
                });

        System.out.println("unavailabilities found: " + unavailabilities.size());
        System.out.println("{");
        for (Unavailability ua : unavailabilities) {
          System.out.println(ua.getPeriod().getFrom() + " - " + ua.getPeriod().getTo());
        }
        System.out.println("}");

        if (!unavailabilities.isEmpty()) {
          for (TimeBox timeBox : Lists.newArrayList(possibleTbs)) {

            System.out.println(
                "check unavailability "
                    + (new DateTime(timeBox.getFrom()).toString("dd/MM/yyyy HH:mm")));

            // Check if there is no unavailabilities for that timebox
            if (!AlgoPlanningUtils.isAvailable(unavailabilities, timeBox)) {
              System.out.println("removing one timebox...");
              possibleTbs.remove(timeBox);
            }
          }
        }

        // let's do it again
        checkPossiblesTimeboxes(participant, possibleTbs, nextPriority);
      }
    }
  }
  public void configure(Planning planning) {

    Validate.notNull(planning);

    this.planning = planning;
    this.rooms = Lists.newArrayList(planning.getRooms());

    if (planning.getPriorities() != null) {
      this.priorities = AlgoPlanningUtils.sortPrioritiesByWeight(planning.getPriorities());
    } else {
      this.priorities = Lists.newArrayList();
    }
  }