Filtering collections with complex conditions