Bug 390470 - o.e.e.p2.core does not select services based on ranking.

When hunting for a service, use the one with the highest ranking.

Change-Id: Idd06b037685602b5a54b6ee767f7ba04b71b443d
Signed-off-by: Wayne Beaton <wayne@eclipse.org>
diff --git a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/ProvisioningAgent.java b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/ProvisioningAgent.java
index 954691d..0a18fef 100644
--- a/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/ProvisioningAgent.java
+++ b/bundles/org.eclipse.equinox.p2.core/src/org/eclipse/equinox/internal/p2/core/ProvisioningAgent.java
@@ -51,16 +51,16 @@
 			if (service != null)
 				return service;
 			//attempt to get factory service from service registry
-			PriorityQueue<ServiceReference<IAgentServiceFactory>> refs;
+			Collection<ServiceReference<IAgentServiceFactory>> refs;
 			try {
-				refs = new PriorityQueue<ServiceReference<IAgentServiceFactory>>(context.getServiceReferences(IAgentServiceFactory.class, "(" + IAgentServiceFactory.PROP_CREATED_SERVICE_NAME + '=' + serviceName + ')')); //$NON-NLS-1$			} catch (InvalidSyntaxException e) {
+				refs = context.getServiceReferences(IAgentServiceFactory.class, "(" + IAgentServiceFactory.PROP_CREATED_SERVICE_NAME + '=' + serviceName + ')'); //$NON-NLS-1$
 			} catch (InvalidSyntaxException e) {
 				e.printStackTrace();
 				return null;
 			}
 			if (refs == null || refs.isEmpty())
 				return null;
-			ServiceReference<IAgentServiceFactory> firstRef = refs.peek();
+			ServiceReference<IAgentServiceFactory> firstRef = Collections.max(refs);
 			//track the factory so that we can automatically remove the service when the factory goes away
 			ServiceTracker<IAgentServiceFactory, Object> tracker = new ServiceTracker<IAgentServiceFactory, Object>(context, firstRef, this);
 			tracker.open();