Added support for ticket type ids at the availability level.
diff --git a/utils/utils.go b/utils/utils.go
index 6e4d65d..c95e198 100644
--- a/utils/utils.go
+++ b/utils/utils.go
@@ -77,30 +77,57 @@
 }
 
 func buildLineItem(availability *fpb.Availability, tickets []*fpb.TicketType) *mpb.LineItem {
+	// If no ticket types return nil as there is nothing to build.
+	if len(tickets) == 0 {
+		return nil
+	}
+
+	// Treated as a set.
+	ticketMap := make(map[string]*fpb.TicketType)
+	for _, ticketType := range tickets {
+		if _, ok := ticketMap[ticketType.GetTicketTypeId()]; !ok {
+			// Ticket type ids should be unique to a merchant service pair.
+			// If they're not unique they will get dropped silently here.
+			// We enforce minimal feed validation in the test client so it's
+			// up to you to ensure UIDs.
+			ticketMap[ticketType.GetTicketTypeId()] = ticketType
+		}
+	}
+
+	filteredTickets := tickets
+	if len(availability.GetTicketTypeId()) != 0 {
+		// Clear slice but preserve allocated memory.
+		filteredTickets = filteredTickets[:0]
+		for _, ticketTypeID := range availability.GetTicketTypeId() {
+			if ticketType, ok := ticketMap[ticketTypeID]; ok {
+				filteredTickets = append(filteredTickets, ticketType)
+			}
+		}
+	}
+
+	// If no ticket types return nil as there is nothing to build.
+	if len(filteredTickets) == 0 {
+		return nil
+	}
+
 	lineItem := &mpb.LineItem{
 		ServiceId:   availability.GetServiceId(),
 		StartSec:    availability.GetStartSec(),
 		DurationSec: availability.GetDurationSec(),
 		Price:       &mpb.Price{},
 	}
-
-	// If not ticket types return nil as there is nothing to build.
-	if len(tickets) == 0 {
-		return nil
-	}
-
 	for i := 0; i < int(availability.GetSpotsOpen()); i++ {
 		// This is deterministic which is fine given that we just want to get a mix of ticket types.
-		ticketTypeIndex := rand.Intn(len(tickets))
+		ticketTypeIndex := rand.Intn(len(filteredTickets))
 		// Calculate price of line item.
-		if lineItem.GetPrice().GetCurrencyCode() == "" && tickets[ticketTypeIndex].GetPrice().GetCurrencyCode() != "" {
-			lineItem.Price.CurrencyCode = tickets[ticketTypeIndex].GetPrice().GetCurrencyCode()
+		if lineItem.GetPrice().GetCurrencyCode() == "" && filteredTickets[ticketTypeIndex].GetPrice().GetCurrencyCode() != "" {
+			lineItem.Price.CurrencyCode = filteredTickets[ticketTypeIndex].GetPrice().GetCurrencyCode()
 		}
-		lineItem.Price.PriceMicros += tickets[ticketTypeIndex].GetPrice().GetPriceMicros()
+		lineItem.Price.PriceMicros += filteredTickets[ticketTypeIndex].GetPrice().GetPriceMicros()
 
 		// Add ticket to line item.
 		lineItem.Tickets = append(lineItem.Tickets, &mpb.LineItem_OrderedTickets{
-			TicketId: tickets[ticketTypeIndex].GetTicketTypeId(),
+			TicketId: filteredTickets[ticketTypeIndex].GetTicketTypeId(),
 			Count:    1,
 		})
 	}