public function getMatchingUnits(\DateTime $start_date, \DateTime $end_date, $valid_states, $constraints = array(), $intersect = FALSE, $reset = TRUE) {
    $units = array();
    $response = new CalendarResponse($start_date, $end_date, $valid_states);
    $keyed_units = $this->keyUnitsById();

    $states = $this->getStates($start_date, $end_date, $reset);
    foreach ($states as $unit => $unit_states) {
      // Create an array with just the states
      $current_states = array_keys($unit_states);

      // Compare the current states with the set of valid states
      if ($intersect) {
        $remaining_states = array_intersect($current_states, $valid_states);
      }
      else {
        $remaining_states = array_diff($current_states, $valid_states);
      }

      if ((count($remaining_states) == 0 && !$intersect) || (count($remaining_states) > 0 && $intersect)) {
        // Unit is in a state that is within the set of valid states so add to result set
        $units[$unit] = $unit;
        $response->addMatch($keyed_units[$unit], CalendarResponse::VALID_STATE);
      }
      else {
        $response->addMiss($keyed_units[$unit], CalendarResponse::INVALID_STATE);
      }

      $unit_constraints = $keyed_units[$unit]->getConstraints();
      $response->applyConstraints($unit_constraints);
    }

    $response->applyConstraints($constraints);

    return $response;
  }