If you want to consume messages in a different order, or consume specific messages at the head, middle or tail of the queue, you can
e.g. here is an example selector
Note that this is not a very efficient way of working with JMS (JMS is designed for consumers to be long lived objects working across many messageS), but it can be useful in certain situations.
Another option is just to use JMX directly to browse messages on a queue, process them and then delete them.