Quintiq file version 2.0 
 | 
#parent: #root 
 | 
Method CleanUpTransportAvailability 
 | 
{ 
 | 
  TextBody: 
 | 
  [* 
 | 
    // Clean up transport availability 
 | 
    // Get a sorted set of all transport availabilities of this unit 
 | 
    sortedtas := selectsortedset( this, TransportAvailability, ta,  
 | 
                                  true,  
 | 
                                  ta.Start() ); 
 | 
                                   
 | 
    head := null( TransportAvailability ); 
 | 
     
 | 
    // Traverse the sorted set of transport availabilities 
 | 
    traverse( sortedtas, Elements, ta ) 
 | 
    { 
 | 
      // Check if there's any transport availability is selected, if there's none, set the current transport availability as selected 
 | 
      if( isnull( head ) ) 
 | 
      { 
 | 
        head := ta; 
 | 
      } 
 | 
     
 | 
      // Get the index of the selected transport availability in the sorted set 
 | 
      headpos := sortedtas.Find( head ); 
 | 
      // Get the next transport availability after the selected transport availability in the sorted set 
 | 
      nextta := guard( sortedtas.Element( headpos + 1 ), null( TransportAvailability ) ); 
 | 
     
 | 
      // Check if there's any next transport availability 
 | 
      if( not isnull( nextta ) ) 
 | 
      { 
 | 
        // Check if the next transport availability has the same data as the selected one 
 | 
        // If the data is the same, remove the next transport availability from the sorted set and dataset 
 | 
        if( head.HasSameData( nextta ) ) 
 | 
        { 
 | 
          sortedtas.Remove( nextta ); 
 | 
          nextta.Delete(); 
 | 
        } 
 | 
        // Else, set the next transport availability as the selected one 
 | 
        else 
 | 
        { 
 | 
          head := nextta; 
 | 
        } 
 | 
      } 
 | 
    } 
 | 
  *] 
 | 
} 
 |