title: How to sort a collection in drools by two properties?
body: <p>I am new to drools, I would like to know how to sort a collection based on two properties of an object.
  The below objects are stored in a collection.</p>
  
  <pre><code>class Schedule{
    private String datePlan;
    private String orderNumber;
    //more fields
  }
  </code></pre>
  
  <p>I tried by configuring the below rule but seems like there is an issue.</p>
  
  <pre><code>rule "ORDER RULE"
      dialect "java"
      when        
          // OrderBy DatePlan asc, OrderNo asc
          not Schedule(planYearMonth == $schedule.planYearMonth,
                              carSeries == $schedule.carSeries,
                              porCode == $schedule.porCode,
                              productionFamilyCode == $schedule.productionFamilyCode,
                              endItemModelCode == $schedule.endItemModelCode,
                              endItemColorCode == $schedule.endItemColorCode,
                              datePlan &lt; $schedule.datePlan || 
                              orderNumber&lt; $schedule.orderNumber))            
  
      then        
  
          retract($order);        
          retract($schedule);
  
  end
  </code></pre>
  
  <p>The below logic is to store Orders &amp; Schedules</p>
  
  <pre><code>rule "insert Orders"    
      when
          $inlist         : OrderList( $inIdx : size &gt; 0)
      then
          for (int i=0; i &lt; $inIdx; i++){
              Order order = (Order)$inlist.get(i);
              insert(order);
          }
          retract($inlist);
  
  end
  
  
  rule "insert Schedules" 
      when
          $inlist         : ScheduleList( $inIdx : size &gt; 0)
      then
          for (int i=0; i &lt; $inIdx; i++){
              Schedule schedule = (Schedule)$inlist.get(i);
              insert(schedule);
          }
          retract($inlist);
  
  end
  </code></pre>